package com.cx.controller.wjj;

/**
 * 王晶晶
 */

import com.cx.pojo.Page;

import com.cx.pojo.wjr.UserPage;
import com.cx.service.wjj.AdminPageService;
import com.cx.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin")
public class AdminPageController {
    @Autowired
    AdminPageService adminPageService;


    @RequestMapping("pageAdd")
    public ResponseResult addPage(ResponseResult responseResult, UserPage userPage) {
        userPage.setPageNum((int)(System.currentTimeMillis()));
        userPage.setSendId((int)Math.random()*100000000);
        userPage.setReceiveId((int)Math.random()*100000000);
        int pageCode=(int)(100000+Math.random()*900000);
        userPage.setPageCode(String.valueOf(pageCode));
        userPage.setStatus("运输中");
        responseResult = adminPageService.addPage(userPage);
        return responseResult;
    }
    @RequestMapping("pageUpdate")
    public ResponseResult updatePage(ResponseResult responseResult,UserPage userPage) {
        if(userPage.getStatus()=="已下单"){
            responseResult = adminPageService.updatePage(userPage);
        }
        return responseResult;

    }
    @RequestMapping("pageDelete")
    public ResponseResult deletePage( ResponseResult responseResult,Integer pageNum) {

         responseResult = adminPageService.deletePage(pageNum);
        return responseResult;
    }

    @RequestMapping("pageSelectAll")
    public ResponseResult selectAll(ResponseResult responseResult) {
        responseResult =  adminPageService.selectAll();
        return responseResult;
    }

    @RequestMapping("pageSelectByMulti")
    public ResponseResult selectByMulti(ResponseResult responseResult,String searchInput) {
        if(searchInput.length()==11){
           responseResult = adminPageService.selectByPhone(searchInput);
        }else if(searchInput.length()==9){
          responseResult =  adminPageService.selectByPageNum(Integer.valueOf(searchInput));
        }else {
            responseResult = adminPageService.selectByName(searchInput);
        }
        return responseResult;
    }
    @RequestMapping("weiXinScan")
    public ResponseResult WeiXinScan(){
        return null;
    }
}
